{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# VAT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "\n",
    "import keras\n",
    "import numpy as np\n",
    "from keras.models import Sequential\n",
    "from keras.layers import Dense, Flatten, Conv2D, MaxPooling2D\n",
    "from keras.datasets import mnist\n",
    "from art.attacks import VirtualAdversarialMethod\n",
    "from art.classifiers import KerasClassifier\n",
    "from art.utils import load_mnist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step.1 完成数据处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "(x_train, y_train), (x_test, y_test), min_pixel_value, max_pixel_value = load_mnist(already_path = 'data/mnist.npz')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "min_pixel_value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max_pixel_value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step.2 搭建模型并训练"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:74: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.\n",
      "\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.\n",
      "\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4138: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.\n",
      "\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3976: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.\n",
      "\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/optimizers.py:790: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.\n",
      "\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:3295: The name tf.log is deprecated. Please use tf.math.log instead.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "model = Sequential()\n",
    "model.add(Conv2D(filters=4, kernel_size=(5, 5), strides=1, activation='relu', input_shape=(28, 28, 1)))\n",
    "model.add(MaxPooling2D(pool_size=(2, 2)))\n",
    "model.add(Conv2D(filters=10, kernel_size=(5, 5), strides=1, activation='relu', input_shape=(23, 23, 4)))\n",
    "model.add(MaxPooling2D(pool_size=(2, 2)))\n",
    "model.add(Flatten())\n",
    "model.add(Dense(100, activation='relu'))\n",
    "model.add(Dense(10, activation='softmax'))\n",
    "\n",
    "model.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.SGD(lr=0.01), metrics=['accuracy'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/math_grad.py:1250: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use tf.where in 2.0, which has the same broadcast rule as np.where\n",
      "WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:986: The name tf.assign_add is deprecated. Please use tf.compat.v1.assign_add instead.\n",
      "\n",
      "Epoch 1/3\n",
      "938/937 [==============================] - 42s 44ms/step - loss: 0.6992 - acc: 0.7894\n",
      "Epoch 2/3\n",
      "938/937 [==============================] - 34s 37ms/step - loss: 0.2327 - acc: 0.9294\n",
      "Epoch 3/3\n",
      "938/937 [==============================] - 35s 37ms/step - loss: 0.1709 - acc: 0.9484\n"
     ]
    }
   ],
   "source": [
    "classifier = KerasClassifier(model=model, clip_values=(min_pixel_value, max_pixel_value), use_logits=False)\n",
    "classifier.fit(x_train, y_train, batch_size=128, nb_epochs=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step.3 测试结果并攻击"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Accuracy on benign test examples: 94.0%\n"
     ]
    }
   ],
   "source": [
    "predictions = classifier.predict(x_test[1000:1100])\n",
    "accuracy = np.sum(np.argmax(predictions, axis=1) == np.argmax(y_test[1000:1100], axis=1)) / len(y_test[1000:1100])\n",
    "print('Accuracy on benign test examples: {}%'.format(accuracy * 100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "attack = VirtualAdversarialMethod(classifier=classifier, max_iter=2, batch_size=50,eps=0.7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "开始第0个Batch\n",
      "开始第0次训练\n",
      "开始第1次训练\n",
      "开始第1个Batch\n",
      "开始第0次训练\n",
      "开始第1次训练\n"
     ]
    }
   ],
   "source": [
    "x_test_adv = attack.generate(x=x_test[1000:1100])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Accuracy on adversarial test examples: 81.0%\n"
     ]
    }
   ],
   "source": [
    "predictions = classifier.predict(x_test_adv)\n",
    "accuracy = np.sum(np.argmax(predictions, axis=1) == np.argmax(y_test[1000:1100], axis=1)) / len(y_test[1000:1100])\n",
    "print('Accuracy on adversarial test examples: {}%'.format(accuracy * 100))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step.4 观看折腾后的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0d28a080>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAFIxJREFUeJzt3X1s1WWWB/DvKbS8tAVakLYgyKhoFklkNg1ugi6uEye6Mb78MUYTEzYxUxNH3QnzxxJiMvjHGjWOs2g2kzCKg8mMM5MwrhiMO8aQOINGAR2VWdcdGLvItrTlpYBQlJezf/SSVOzvey73d9/w+X4S0vae+9z7cHtPb2/P8zzH3B0ikp6GWk9ARGpDyS+SKCW/SKKU/CKJUvKLJErJL5IoJb9IopT8IolS8oskamI178zMKraccOJE/l85depUpe4aZpYrnteZM2cyYxMmTKjofTc08NcP9rjnfVwquTo1721Hjwv7nuXl7kU9sLmS38xuArAWwAQAz7r7Y3luL4+ZM2fS+MDAAI1HScKeqNEPnigeJcHp06dp/MSJE5mxGTNm0LF5NTU10fj+/fszY5MnT6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l8kUUp+kUQp+UUSpeQXSZSSXyRRSn6RRP0/rq4nsWN6hbMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f4a25d8d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from matplotlib import pyplot as plt\n",
    "\n",
    "plt.imshow(x_test_adv[0,:,:,0], cmap='gray')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f0d25ea58>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAADP5JREFUeJzt3W+oVPedx/HPx6Q+USF/jKlYm3QlrFkCscslSCzFUCxpNRgfNDQk4MLaW0iFK/TBqk9qHiyUpX+TB4YrvdQEm1rSdiOk2SihYBuWEBOksVprUoy1MdpiSSMEivrdB/e43Jo7vxlnzsyZe7/vF8jMnO+Zc74Mfu45M+fPzxEhAPnMaboBAM0g/EBShB9IivADSRF+ICnCDyRF+IGkCD+QFOEHkrp+kCuzzemEQJ9FhDuZr6ctv+37bR+3/Zbtrb0sC8Bgudtz+21fJ+n3ktZIOi3pNUkPR8TRwnvY8gN9Nogt/z2S3oqIP0TE3yX9WNL6HpYHYIB6Cf8SSX+c8vp0Ne0f2B61fcj2oR7WBaBmvfzgN92uxUd26yNiXNK4xG4/MEx62fKflrR0yutPSHq3t3YADEov4X9N0h22P2V7rqQvS9pXT1sA+q3r3f6IuGh7s6SXJF0naSIifltbZwD6qutDfV2tjO/8QN8N5CQfADMX4QeS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PV9EY/u0JfjXxuA9/tt32dpN9LWiPptKTXJD0cEUcH2kgLtk9KGomIxo8J2/6spAuSno6Iu6pp/yXpfER8s/rDeWNE/MeQ9LZD0oWmR26uBpRZPHVkaUkPSvo3NfjZFfp6SA18bk1s+e+R9FZE/CEi/i7px5LWN9DH0IuIg5LOXzV5vaTd1fPdmvzPM3AtehsKEXEmIt6onn8g6crI0o1+doW+GtFE+JdI+uOU16c1XEN+h6T9tl+3Pdp0M9O49crISNXjoob7uVrbkZsH6aqRpYfms+tmxOu6NRH+6W4xNEyHHFZFxL9K+oKkr1W7t+hMRyM3D8o0I0sPhW5HvK5bE+E/LWnplNefkPRuA31MKyLerR7PSfq5hm/04bNXBkmtHs813M//G6aRm6cbWVpD8NkN04jXTYT/NUl32P6U7bmSvixpXwN9fITtedUPMbI9T9LnNXyjD++TtLF6vlHS8w328g+GZeTmViNLq+HPbthGvG7kJJ/qUMb3JF0naSIi/nPgTUzD9j9pcmsvTV7x+KMme7P9rKTVmrzq66ykb0j6b0k/kfRJSackfSkiBv7DW4veVusaR27uU2+tRpZ+VQ1+dnWOeF1LP5zhB+TEGX5AUoQfSIrwA0kRfiApwg8kRfiBpAg/kBThB5L6P5L3zOQk0Bd7AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f0d295be0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(x_test[1000,:,:,0], cmap='gray')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
